package com.xmotor.test_httpclient.client;

import com.xmotor.test_httpclient.util.HttpClientUtil;
import com.xmotor.test_httpclient.util.HttpResult;

import java.util.Map;

public class TestClient {
    private String domain;

    private TestClient(String domain) {
        this.domain = domain;
    }

    private static volatile TestClient testClient;

    public static TestClient getInstance(String domain){
        if (testClient == null){
            synchronized (TestClient.class){
                if (testClient == null){
                    testClient = new TestClient(domain);
                }
            }
        }
        return testClient;
    }

    public String doGet(String api, Map<String,String> param){
        HttpResult result = HttpClientUtil.sendGet(domain+api, param, null, null, "UTF-8");
        return result.getStringContent();
    }

    public String doPostForm(String api, Map<String,String> param){
        HttpResult result = HttpClientUtil.sendPostForm(domain+api, param, null, null, "UTF-8");
        return result.getStringContent();
    }

    public String doPostJson(String api, String jsonParam){
        HttpResult result = HttpClientUtil.sendPostJson(domain+api, jsonParam, null, null, "UTF-8");
        return result.getStringContent();
    }
}
